<template>
	<view>
		<!-- #ifdef APP-PLUS -->
		<view><uni-nav-bar left-icon="arrowleft" @clickLeft="back" title="支付完成" :statusBar="true" :fixed="true"></uni-nav-bar></view>
		<!-- #endif -->
		<view class="paysuccess">
			<image :src="commonImg('paysuccess.png')" class="paysuccess-img"></image>
			<text class="paysuccess-statustxt">支付成功</text>
			<text class="paysuccess-shopname">{{ storeInfo.storeName }}</text>
			<text class="paysuccess-pricetxt">￥{{ payAmount }}</text>
			<view class="paysuccess-desc">
				<text class="paysuccess-desc-firsttxt">码上结</text>
				<text class="paysuccess-desc-firsttxt">去哪消费都打折</text>
			</view>
			<view @click="onClickGotoBack" class="paysuccess-back">返回</view>
		</view>
	</view>
</template>
<script>
import { myMixin } from '@/utils/mixin.js';
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import { config } from '@/utils/config.js';

export default {
	mixins: [myMixin],
	data() {
		return {
			storeInfo: {},
			payAmount: 0,
			ordersId: ''
		};
	},
	methods: {
		back() {
			uni.navigateBack({});
		},
		onClickGotoBack() {
			uni.navigateBack({});
		},
		_getStoreInfoByStoreId() {
			uni.request({
				url: `${config.api_base_url}merchant/store/${this.storeId}`,
				header: {
					AUTH: 'ROBOT ' + uni.getStorageSync('token')
				},
				success: res => {
					let { status, data } = res.data;
					if (status.flag === true) {
						this.storeInfo = data;
					} else {
						this.storeInfo = {};
					}
				},
				fail: () => {
					this.storeInfo = {};
				}
			});
		},
		_sendOrderId() {
			uni.request({
				url: `${config.api_base_url}orders/pay/queryOrders/${this.ordersId}`,
				header: {
					AUTH: 'ROBOT ' + uni.getStorageSync('token')
				},
				success: res => {
					let { status, data } = res.data;
					if (status.flag === true) {
						uni.removeStorageSync('myOrdersId');
					} else {
						uni.showToast({
							icon: 'none',
							title: status.msg
						});
					}
				},
				fail: () => {
					uni.showToast({
						icon: 'none',
						title: '发送订单号失败, 网络异常'
					});
				}
			});
		},
		_SendCodeBean() {
			uni.request({
				url: `${config.api_base_url}member/member/findByToken`,
				header: {
					AUTH: 'ROBOT ' + uni.getStorageSync('token')
				},
				success: ((res) =>{
					let { status, data } = res.data
					if(data.data.phone == null && data.data.phone =="" ){
						uni.navigateTo({url:"../writetel/writetel.vue"})
					}
				})
			})
		}
	},
	components: {
		uniNavBar
	},
	onLoad(e) {
		if (e && e.storeId && e.payAmount) {
			this.storeId = e.storeId;
			this.payAmount = e.payAmount;
			this._getStoreInfoByStoreId();
			this._SendCodeBean();
		}
		if (uni.getStorageSync('myOrdersId')) {
			this.ordersId = uni.getStorageSync('myOrdersId');
			this._sendOrderId();
		}
	}
};
</script>

<style>
page {
	background-color: #fff;
}
</style>
<style scoped>
.paysuccess {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	box-sizing: border-box;
	padding-top: 72rpx;
}
.paysuccess-img {
	width: 88rpx;
	height: 88rpx;
	border-radius: 50%;
}
.paysuccess-statustxt {
	margin-top: 32rpx;
	font-weight: 500;
	font-size: 40rpx;
	line-height: 56rpx;
	color: #000000;
}
.paysuccess-shopname {
	font-size: 28rpx;
	line-height: 40rpx;
	font-weight: 400;
	color: rgba(0, 0, 0, 0.85);
}
.paysuccess-pricetxt {
	font-size: 28rpx;
	line-height: 40rpx;
	font-weight: 400;
	color: rgba(0, 0, 0, 0.85);
}
.paysuccess-desc {
	width: 650rpx;
	height: 350rpx;
	display: flex;
	background-color: #d8d8d8;
	border-radius: 12rpx;
	flex-direction: column;
	justify-content: center;
}
.paysuccess-desc-firsttxt {
	font-size: 28rpx;
	font-weight: 500;
	line-height: 40rpx;
	color: rgba(0, 0, 0, 0.85);
	display: block;
	margin-left: 206rpx;
}
.paysuccess-back {
	font-size: 36rpx;
	margin-top: 52rpx;
	line-height: 50rpx;
	color: rgba(0, 0, 0, 0.85);
	font-weight: 400;
}
</style>
